
**-----------------------------------------------------

			* premise: install packages

**-----------------------------------------------------

*Set working directory
cd "~/r&r"

ssc install ftools, replace
ssc install reghdfe, replace
ssc install ivreg2, replace
ssc install ivreghdfe, replace
ssc install outreg2, replace
ssc install spmap, replace
ssc install acreg, replace
ssc install balancetable, replace
net install rdrobust, from(https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata) replace
ssc install ssaggregate, replace
 
**-----------------------------------------------------

			* Manuscript

**-----------------------------------------------------

u "data/panel_mafiaconsmig", clear
drop if iddecade==1|iddecade==4 // drop 1951, 1981, keep analysis period (1961, 1971)


*Figure 1: Mafia presence as defined by news, 1960–1989, and official indicators, 1990–2018

preserve
	bys municipalities: egen newsmax=max(news)
	keep if iddecade==2
	
	format mafiamean_any %5.3f
	su mafiamean_any
	local min=r(min)
	di `min'
	su mafiamean_any,d,if mafiamean_any>`min'+0.0001
	local max=r(max)
	local min2=r(min)
	di `min2'
	local p10=r(p10)
	local p50=r(p50)
	local p95=r(p95)
	
		spmap mafiamean_any using "data/city-coord.dta", id(id) fcolor(Reds) ocolor(none none none none none) clmethod(custom) clbreaks(`min' `min2'  `p50' `p95' `max') title("Official indicators 1991-2018") name(anyindicator, replace)
	
	su newsmax,d
	local min=r(min)
	local max=r(max)
	su newsmax,d,if newsmax>`min'+0.00001
	local min2=r(min)
	local p50=r(p50)
	local p95=r(p95)
	
	spmap newsmax using "data/city-coord.dta", id(id) ocolor(none none none none none) fcolor(Reds) clmethod(custom) clbreaks(`min' `min2' `p50' `p95' `max') title("Mafia-related news 1960-1989") name(anynews, replace)
	
		graph combine anynews anyindicator
		graph export "figures/figure1.pdf", as(pdf) replace
restore
	
	
* Table 1: Determinants of mafia expansion
	
	su newspc
	local meandv=round(r(mean), 0.001)
	
	*ols
	 ivreghdfe newspc zempcp zmigshare zem ipop, abs(municipalities iddecade) cluster(municipalities)
		outreg2 using "tables/table1", replace tex label dec(4) keep(zempcp zmigshare zem) addtext(City Decade FE, Yes, Mean DV, `meandv') nocons nor2 
	 
	 *iv
	 ivreghdfe newspc (zempcp zmigshare zem = zssc zssmig zss) ipop, abs(municipalities iddecade) first savefirst cluster(municipalities) 
		outreg2 using "tables/table1", tex label dec(3) keep(zempcp zmigshare zem) addtext(City Decade FE, Yes, Mean DV, `meandv') nocons nor2 
		
	
	
*Figure 2: Effect of construction and migration on mafia, by levels of the other variable

		xtreg zempcp zssc zssmig zss dec2 dec3 ipop, fe cluster(municipalities)
		predict zempcp_xb
		
		xtreg zmigshare zssc zssmig zss  dec2 dec3 ipop, fe cluster(municipalities)
		predict zmigshare_xb
		
		xtile zmig=zmigshare_xb, nq(4)
		xtile zcon=zempcp_xb, nq(4)
		
		forval i=1/4 {
			reghdfe newspc zempcp_xb dec2 dec3 ipop if zmig==`i', abs(municipalities iddecade) cluster(municipalities)
			eststo c`i'
		}
		coefplot (c1, msymbol(circle) mcolor(blue) ciopts(lcolor(blue))) (c2, msymbol(circle) mcolor(blue) ciopts(lcolor(blue)))(c3, msymbol(circle) mcolor(blue) ciopts(lcolor(blue)))(c4, msymbol(circle) mcolor(blue) ciopts(lcolor(blue))), keep(zempcp_xb) vertical ytitle(Effect of Predicted Construction on Mafia) xtitle(Predicted Southern Migration) xlab(0.7 "Low" 1 "Medium" 1.35 "High") legend(off) yline(0)
		graph save interflex1.gph, replace
	
	
	forval i=1/4 {
			cap reghdfe newspc zmigshare_xb dec2 dec3 ipop if zcon==`i', abs(municipalities iddecade) cluster(municipalities)
			cap eststo c`i'
		}
		coefplot (c1, msymbol(circle) mcolor(plg2) ciopts(lcolor(plg2)))(c2, msymbol(circle) mcolor(plg2) ciopts(lcolor(plg2)))(c3, msymbol(circle) mcolor(plg2) ciopts(lcolor(plg2)))(c4, msymbol(circle) mcolor(plg2) ciopts(lcolor(plg2))), keep(zmigshare_xb) vertical ytitle(Effect of Predicted Migration  on Mafia) xtitle(Predicted Construction Employment) xlab(0.75 "Low" 1 "Medium" 1.25 "High") legend(off) yline(0)
				graph save interflex2.gph, replace

		graph combine interflex1.gph interflex2.gph
		graph export "figures/figure2.pdf", as(pdf) replace
		erase interflex1.gph
		erase interflex2.gph 
	
	